<html>
<head>
<link rel="stylesheet" type="text/css" href="./style.css" />
</head>
<img style="margin-left:42%; text-align:center" src="./img/logo_txt_only.jpg" />
<div style="text-align:center;background-color:#d0ddcf;border: 1px solid #9CAA9C;width:300px;margin-left:40%;margin-left:40%;">
<?php

include('functions.php');

dbConnect();

if(isset($_GET['signup'])){ //Send eMail Catch
	
	
	$usr = $_POST['username'];
	$dom = $_POST['domain'];

	
	$result = mysql_query("SELECT domain FROM domains");

	while($row = mysql_fetch_assoc($result)){
		if($row['domain'] == $dom){
			
			$found_domain = true;
		}
	}
	
	$domainCheck = mysql_query("SELECT domain FROM domains WHERE domain='$dom'");

	$domainCheckNum = @mysql_num_rows($domainCheck);
	
	$verCheck = mysql_query("SELECT ver FROM vers WHERE username = '$usr' AND domain = '$dom'");;
	
	
	if($domainCheckNum!=0){
		
		$usernameCheck = mysql_query("SELECT status FROM users WHERE username='$usr' AND domain='$dom'");
		
		$fullName = $usr . '@' . $dom;


		if(@mysql_num_rows($usernameCheck) != 0){
			
			$userArray = mysql_fetch_array($usernameCheck);
			
			if($userArray[0]=='banned'){

				echo 'Your email address ' . $fullName . ' has been banned, your IP has been logged';

				logAction($_SERVER['REMOTE_ADDR'], 'Attempted Banned User Login ' . $fullName);
				
			} else {
				echo '<br /><b>But! Sorry, you already have an account at College Hustler</b><br />';
				echo 'Click <a href="recover.php"> here </a> to recover your password for ' . $usr . '@' . $dom . '<br />';
			}
			
		} else {
			
			//echo $key . '<br />';
			
			if(mysql_num_rows($verCheck) > 0){
				 $verCheckArray = mysql_fetch_array($verCheck);		
				 $key = $verCheckArray[0];	
			 echo 'We have already sent you a verification email, we will send another!<br />';
			} else {
				$key = md5(uniqid(rand(), true));
				mysql_query("INSERT INTO vers (ver, username, domain, type) VALUES ('$key', '$usr', '$dom', 'signup')");
			}
	
			echo 'We have sent a verification email to ' . $fullName .  '!<br />';
			echo 'Check your Spam folder for the validation email if you do not receive it in your inbox, the word "hustler" tends to place our emails in univesity spam boxes<br />';

			$theURL = getUrl();
			
			$email = $fullName;
			$subject = '<br />CollegeHustler.com verification code!';
			$content = 'Welcome to College Hustler.com! Click this link to verify your email adress and start Hustling!</p>';
			$content = $content . ' ' . $theURL . 'passChoose.php?register=' . $key . ' ';
			$headers = 'From: doNotReply@collegeHustler.com' . "\r\n";
			
			//echo '<br />' . $content . '<br />';
			
			mail($email, $subject, $content, $headers);
		}
		
	} else {
		
		echo ' Your domain is not a domain we allow on CollegeHustler.com, sorry';
		
	}
		mysql_close();
}

?>

</div>

<a style="margin-top:20px;margin-left:48%;text-align:center;color:black" href="<?= getUrl(); ?>">Return Home</a>

</html>